<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=0CvtAlhApwopQjEVimtFXKT9xZegPKNM"></script>
    <script type="text/javascript" src="https://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js"></script>
<!--    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>-->
    <title>热力图功能示例</title>
<style type="text/css">
    ul,
    li {
        list-style: none;
        margin: 0;
        padding: 0;
        float: left;
    }

    html,
    body {
        height: 100%;
        margin: 0;
        padding: 0;
        font-family: "微软雅黑";
    }

    #container {
        height: 100%;
        width: 100%;
    }
</style>

</head>

<body>
    <div id="container"></div>
</body>



</html>
<script type="text/javascript">
    var points = {{ points|safe }};

    function loadHeatmapData() {
        if (Array.isArray(points) && points.length > 0 && points[0].hasOwnProperty('lng') && points[0].hasOwnProperty('lat') && points[0].hasOwnProperty('count')) {
            heatmapOverlay.setDataSet({ data: points, max: 15 });
            heatmapOverlay.show();
        } else {
            console.error("数据格式不正确");
        }
    }

    var map = new BMap.Map("container"); // 创建地图实例
    var point = new BMap.Point(116.418261, 39.921984);
    map.centerAndZoom(point, 12); // 初始化地图，设置中心点坐标和地图级别
    map.enableScrollWheelZoom(true); // 允许滚轮缩放

    if (!isSupportCanvas()) {
        alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~');
    }

    var heatmapOverlay = new BMapLib.HeatmapOverlay({ "radius": 20 });
    map.addOverlay(heatmapOverlay);

    loadHeatmapData(); // 自动加载并显示热力图

    function isSupportCanvas() {
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    }
</script>


